/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package emf.entity_relationship.model.entityrelationship.impl;

import emf.entity_relationship.model.entityrelationship.Attribute;
import emf.entity_relationship.model.entityrelationship.Connection_Entity_Relationship;
import emf.entity_relationship.model.entityrelationship.EntityrelationshipPackage;
import emf.entity_relationship.model.entityrelationship.Relationship;
import emf.entity_relationship.model.entityrelationship.TypeCardinality;
import emf.entity_relationship.model.entityrelationship.TypeRelationship;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Relationship</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link emf.entity_relationship.model.entityrelationship.impl.RelationshipImpl#getName_relationship <em>Name relationship</em>}</li>
 *   <li>{@link emf.entity_relationship.model.entityrelationship.impl.RelationshipImpl#getOrder <em>Order</em>}</li>
 *   <li>{@link emf.entity_relationship.model.entityrelationship.impl.RelationshipImpl#getCardinality <em>Cardinality</em>}</li>
 *   <li>{@link emf.entity_relationship.model.entityrelationship.impl.RelationshipImpl#getType_relationship <em>Type relationship</em>}</li>
 *   <li>{@link emf.entity_relationship.model.entityrelationship.impl.RelationshipImpl#getAttributes_relationship <em>Attributes relationship</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class RelationshipImpl extends EObjectImpl implements Relationship {
	/**
	 * The default value of the '{@link #getName_relationship() <em>Name relationship</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName_relationship()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_RELATIONSHIP_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName_relationship() <em>Name relationship</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName_relationship()
	 * @generated
	 * @ordered
	 */
	protected String name_relationship = NAME_RELATIONSHIP_EDEFAULT;

	/**
	 * The default value of the '{@link #getOrder() <em>Order</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOrder()
	 * @generated
	 * @ordered
	 */
	protected static final int ORDER_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getOrder() <em>Order</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOrder()
	 * @generated
	 * @ordered
	 */
	protected int order = ORDER_EDEFAULT;

	/**
	 * The default value of the '{@link #getCardinality() <em>Cardinality</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCardinality()
	 * @generated
	 * @ordered
	 */
	protected static final String CARDINALITY_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getCardinality() <em>Cardinality</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCardinality()
	 * @generated
	 * @ordered
	 */
	protected String cardinality = CARDINALITY_EDEFAULT;

	/**
	 * The default value of the '{@link #getType_relationship() <em>Type relationship</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType_relationship()
	 * @generated
	 * @ordered
	 */
	protected static final TypeRelationship TYPE_RELATIONSHIP_EDEFAULT = TypeRelationship.REGULAR;

	/**
	 * The cached value of the '{@link #getType_relationship() <em>Type relationship</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getType_relationship()
	 * @generated
	 * @ordered
	 */
	protected TypeRelationship type_relationship = TYPE_RELATIONSHIP_EDEFAULT;

	/**
	 * The cached value of the '{@link #getAttributes_relationship() <em>Attributes relationship</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getAttributes_relationship()
	 * @generated
	 * @ordered
	 */
	protected EList<Attribute> attributes_relationship;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected RelationshipImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return EntityrelationshipPackage.Literals.RELATIONSHIP;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName_relationship() {
		return name_relationship;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName_relationship(String newName_relationship) {
		String oldName_relationship = name_relationship;
		name_relationship = newName_relationship;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EntityrelationshipPackage.RELATIONSHIP__NAME_RELATIONSHIP, oldName_relationship, name_relationship));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getOrder() {
		return order;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setOrder(int newOrder) {
		int oldOrder = order;
		order = newOrder;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EntityrelationshipPackage.RELATIONSHIP__ORDER, oldOrder, order));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getCardinality() {
		return cardinality;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCardinality(String newCardinality) {
		String oldCardinality = cardinality;
		cardinality = newCardinality;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EntityrelationshipPackage.RELATIONSHIP__CARDINALITY, oldCardinality, cardinality));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public TypeRelationship getType_relationship() {
		return type_relationship;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setType_relationship(TypeRelationship newType_relationship) {
		TypeRelationship oldType_relationship = type_relationship;
		type_relationship = newType_relationship == null ? TYPE_RELATIONSHIP_EDEFAULT : newType_relationship;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, EntityrelationshipPackage.RELATIONSHIP__TYPE_RELATIONSHIP, oldType_relationship, type_relationship));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Attribute> getAttributes_relationship() {
		if (attributes_relationship == null) {
			attributes_relationship = new EObjectContainmentEList<Attribute>(Attribute.class, this, EntityrelationshipPackage.RELATIONSHIP__ATTRIBUTES_RELATIONSHIP);
		}
		return attributes_relationship;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case EntityrelationshipPackage.RELATIONSHIP__ATTRIBUTES_RELATIONSHIP:
				return ((InternalEList<?>)getAttributes_relationship()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case EntityrelationshipPackage.RELATIONSHIP__NAME_RELATIONSHIP:
				return getName_relationship();
			case EntityrelationshipPackage.RELATIONSHIP__ORDER:
				return getOrder();
			case EntityrelationshipPackage.RELATIONSHIP__CARDINALITY:
				return getCardinality();
			case EntityrelationshipPackage.RELATIONSHIP__TYPE_RELATIONSHIP:
				return getType_relationship();
			case EntityrelationshipPackage.RELATIONSHIP__ATTRIBUTES_RELATIONSHIP:
				return getAttributes_relationship();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case EntityrelationshipPackage.RELATIONSHIP__NAME_RELATIONSHIP:
				setName_relationship((String)newValue);
				return;
			case EntityrelationshipPackage.RELATIONSHIP__ORDER:
				setOrder((Integer)newValue);
				return;
			case EntityrelationshipPackage.RELATIONSHIP__CARDINALITY:
				setCardinality((String)newValue);
				return;
			case EntityrelationshipPackage.RELATIONSHIP__TYPE_RELATIONSHIP:
				setType_relationship((TypeRelationship)newValue);
				return;
			case EntityrelationshipPackage.RELATIONSHIP__ATTRIBUTES_RELATIONSHIP:
				getAttributes_relationship().clear();
				getAttributes_relationship().addAll((Collection<? extends Attribute>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case EntityrelationshipPackage.RELATIONSHIP__NAME_RELATIONSHIP:
				setName_relationship(NAME_RELATIONSHIP_EDEFAULT);
				return;
			case EntityrelationshipPackage.RELATIONSHIP__ORDER:
				setOrder(ORDER_EDEFAULT);
				return;
			case EntityrelationshipPackage.RELATIONSHIP__CARDINALITY:
				setCardinality(CARDINALITY_EDEFAULT);
				return;
			case EntityrelationshipPackage.RELATIONSHIP__TYPE_RELATIONSHIP:
				setType_relationship(TYPE_RELATIONSHIP_EDEFAULT);
				return;
			case EntityrelationshipPackage.RELATIONSHIP__ATTRIBUTES_RELATIONSHIP:
				getAttributes_relationship().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case EntityrelationshipPackage.RELATIONSHIP__NAME_RELATIONSHIP:
				return NAME_RELATIONSHIP_EDEFAULT == null ? name_relationship != null : !NAME_RELATIONSHIP_EDEFAULT.equals(name_relationship);
			case EntityrelationshipPackage.RELATIONSHIP__ORDER:
				return order != ORDER_EDEFAULT;
			case EntityrelationshipPackage.RELATIONSHIP__CARDINALITY:
				return CARDINALITY_EDEFAULT == null ? cardinality != null : !CARDINALITY_EDEFAULT.equals(cardinality);
			case EntityrelationshipPackage.RELATIONSHIP__TYPE_RELATIONSHIP:
				return type_relationship != TYPE_RELATIONSHIP_EDEFAULT;
			case EntityrelationshipPackage.RELATIONSHIP__ATTRIBUTES_RELATIONSHIP:
				return attributes_relationship != null && !attributes_relationship.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name_relationship: ");
		result.append(name_relationship);
		result.append(", order: ");
		result.append(order);
		result.append(", cardinality: ");
		result.append(cardinality);
		result.append(", type_relationship: ");
		result.append(type_relationship);
		result.append(')');
		return result.toString();
	}

} //RelationshipImpl
